from fastapi import APIRouter

from app.database.postgre import SessionDep
from app.models.common import VersionIdJSON, VersionIdParams, AppIdJSON
from app.models.versions import (AppVersionListParams, CreateAppVersionJSON, UpdateAppVersionJSON,
                                 PublishAppVersionJSON, EnforceAppVersionJSON, BatchDeleteAppVersionsJSON)
from app.services import accounts, versions

router = APIRouter(
    prefix='/api/v1/versions',
    tags=['backend', 'versions']
)


@router.get('/list')
async def app_versions_list(
        account: accounts.LoggedInAccount,
        query_params: AppVersionListParams,
        session: SessionDep):
    response = await versions.get_app_versions_list(account, query_params, session)
    return response


@router.get('/info')
async def app_version_info(account: accounts.LoggedInAccount, query_params: VersionIdParams, session: SessionDep):
    response = await versions.get_app_version_info(account, query_params, session)
    return response


@router.post('/create')
async def create_app_version(account: accounts.LoggedInAccount, json_data: CreateAppVersionJSON, session: SessionDep):
    response = await versions.create_new_app_version(account, json_data, session)
    return response


@router.post('/delete')
async def delete_app_version(account: accounts.LoggedInAccount, json_data: VersionIdJSON, session: SessionDep):
    response = await versions.delete_app_version(account, json_data, session)
    return response


@router.post('/batch_delete')
async def batch_delete_app_versions(account: accounts.LoggedInAccount, json_data: BatchDeleteAppVersionsJSON,
                                    session: SessionDep):
    response = await versions.batch_delete_app_versions(account, json_data, session)
    return response


@router.post('/clear')
async def clear_app_versions(account: accounts.LoggedInAccount, json_data: AppIdJSON, session: SessionDep):
    response = await versions.clear_all_app_versions(account, json_data, session)
    return response


@router.post('/update')
async def update_app_version(account: accounts.LoggedInAccount, json_data: UpdateAppVersionJSON, session: SessionDep):
    response = await versions.update_app_version(account, json_data, session)
    return response


@router.post('/publish')
async def publish_app_version(account: accounts.LoggedInAccount, json_data: PublishAppVersionJSON, session: SessionDep):
    response = await versions.publish_app_version(account, json_data, session)
    return response


@router.post('/enforce')
async def publish_app_version(account: accounts.LoggedInAccount, json_data: EnforceAppVersionJSON, session: SessionDep):
    response = await versions.enforce_app_version(account, json_data, session)
    return response
